#include "Logger.h"
#include <chrono>
#include <cstddef>
#include <thread>
#include "ThreadPool.h" // 包含你的 ThreadPool 实现



// 一个简单的辅助函数，用于打印线程 ID 和任务信息
void PrintTask(const std::string& task_name) {
    // GS_INFO("happy");
    size_t hash = std::hash<std::thread::id>{}(std::this_thread::get_id());
    GS_INFO("{0} executed on thread {1}", task_name, hash);
}

int main() {

    GiSo::Logger::Options options;
    options.outputType = GiSo::Logger::OutputType::Both;
    options.filename = "my_app.log";
    GiSo::Logger::init(options);

    // 创建线程池，指定 3 个线程
    GiSo::ThreadPool pool(3);

        // 获取各个线程的任务队列
    auto queue0 = pool.GetQueue(0);
    auto queue1 = pool.GetQueue(1);
    auto queue2 = pool.GetQueue(2);

    // 测试 1: 向每个队列提交单个任务
    GS_INFO("Test 1: Submit one task to each queue");
    queue0->PushBack([]() { PrintTask("Task 1"); });
    queue1->PushBack([]() { PrintTask("Task 2"); });
    queue2->PushBack([]() { PrintTask("Task 3"); });

    // 等待片刻，确保任务执行
    std::this_thread::sleep_for(std::chrono::milliseconds(100));

    // 测试 2: 向队列 0 提交多个任务，测试连续执行
    GS_INFO("Test 2: Submit multiple tasks to queue 0");
    for (int i = 4; i <= 6; ++i) {
        queue0->PushBack([i]() { PrintTask("Task " + std::to_string(i)); });
    }

    // 等待片刻
    std::this_thread::sleep_for(std::chrono::milliseconds(100));

    // 测试 3: 模拟高负载，向所有队列提交任务
    GS_INFO("Test 3: Submit tasks to all queues");
    for (int i = 7; i <= 9; ++i) {
        queue0->PushBack([i]() { PrintTask("Task " + std::to_string(i) + " on queue 0"); });
        queue1->PushBack([i]() { PrintTask("Task " + std::to_string(i) + " on queue 1"); });
        queue2->PushBack([i]() { PrintTask("Task " + std::to_string(i) + " on queue 2"); });
    }

    // 等待所有任务完成
    std::this_thread::sleep_for(std::chrono::milliseconds(1000));

    // pool.Stop();

    // 线程池析构时会自动停止并清理
    GS_INFO("Test completed, ThreadPool shutting down...");
    return 0;


}